package org.duang.lock;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.duang.config.Config;
import org.duang.kit.ToolsKit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 基于Curator,创建ClientFactory
 * @author laotang
 */
public class ZkClientFactory {
	
	private static final Logger logger = LoggerFactory.getLogger(ZkClientFactory.class);

	public static CuratorFramework init() {
		if(ToolsKit.isEmpty(Config.getZKSyncLockHost())){
			logger.warn("zookeeper host is empty!");
			return null;
		}
		ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
		return CuratorFrameworkFactory.newClient(Config.getZKSyncLockHost(), retryPolicy);
	}
	 
}
